package com.leexuan.ordersystem.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DB {

	protected Connection conn;

	public Connection getConnection() {

		Connection con = null;
		try {
			String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
			String url = "jdbc:Microsoft:Sqlserver://132.232.28.32:1433;DatabaseName=OrderSystem";
			String username = "sa";
			String password = "123";
			Class.forName(driver).newInstance();
			con = DriverManager.getConnection(url, username, password);

			this.conn = con;
			return con;
		} catch (ClassNotFoundException e) {

			e.printStackTrace();
			return null;
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}

	}

	public void closeConnection() {
		if (this.conn != null) {
			try {
				conn.close();
				conn = null;
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}

	}
}
